package com.liukh.obwiki.controller;

import com.liukh.obwiki.req.EbookQueryReq;
import com.liukh.obwiki.req.EbookSaveReq;
import com.liukh.obwiki.resp.CommonResp;
import com.liukh.obwiki.resp.EbookQueryResp;
import com.liukh.obwiki.resp.PageResp;
import com.liukh.obwiki.service.IEbookService;


import javax.validation.Valid;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 电子书 前端控制器
 * </p>
 *
 * @author cr
 * @since 2025-06-22
 */
@RestController
@RequestMapping("/ebook")
@Api("电子书接口")
public class EbookController {
    @Autowired
    private IEbookService ebookService;

    @GetMapping("/list")
    @ApiOperation("查询电子书接口")
    public CommonResp list(@Valid EbookQueryReq req) {
        CommonResp<PageResp<EbookQueryResp>> resp = new CommonResp<>(true,"查询成功",null);
        PageResp<EbookQueryResp> list = ebookService.listByname(req);
        resp.setContent(list);
        return resp;
    }

    @PostMapping("/save")
    @ApiOperation("保存电子书接口")
    public CommonResp save(@Valid @RequestBody EbookSaveReq req) {
        CommonResp resp = new CommonResp<>(true,"成功",null);
        ebookService.save(req);
        return resp;
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除电子书接口")
    public CommonResp delete(@PathVariable Long id) {
        CommonResp resp = new CommonResp<>();
        ebookService.delete(id);
        resp.setMessage("删除成功");
        resp.setSuccess(true);
        return resp;
    }
}
